package sample.util;

/**
 * Created by 杨家兵 on 2017/1/10.
 */
import java.io.File;
import javafx.stage.FileChooser;
import javafx.stage.Stage;



public  class FileChooserSample {
    public static String filePath;
    public static String fileName;
    public static void fileChooserDilog(Stage stage,String firstPath,String firstName){
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Open Resource File");
        System.out.println(firstPath);
        if(null!=firstPath&&!"".equals(firstPath)){
            System.out.println(firstPath);
            System.out.println(firstName);
            fileChooser.setInitialDirectory(new File(firstPath.replace(firstName,"").trim()));
            File file=fileChooser.showOpenDialog(stage);
            try {
                filePath = file.getAbsolutePath();
                fileName = file.getName();
            }catch (NullPointerException e){}
        }else {
            File file=fileChooser.showOpenDialog(stage);
            try {
                filePath = file.getAbsolutePath();
                fileName = file.getName();
            }catch (NullPointerException e){}
        }
    }
    public static void fileFirstChooserDilog(Stage stage){
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Open Resource File");
        File file=fileChooser.showOpenDialog(stage);
        try {
            filePath = file.getAbsolutePath();
        }catch (NullPointerException e){}

    }
}
